import request from 'src/api/request';

export default function(repository) {
    return {
        fetchPage(query) {
            query.list = null;
            return request({
                url: '/' + repository,
                method: 'GET',
                params: query
            });
        },
        fetchAll() {
            return request({
                url: '/' + repository,
                method: 'GET',
                params: {
                    page: 0,
                    size: 1000
                }
            });
        },
        search(params) {
            return request({
                url: '/' + repository + '/search',
                method: 'GET',
                params
            });
        },
        getModel(id) {
            return request({
                url: '/' + repository + '/' + id,
                method: 'GET'
            });
        },
        /**
         * 创建一个新的实例
         */
        postModel(entity) {
            return request({
                url: '/' + repository,
                method: 'POST',
                data: JSON.stringify(entity)
            });
        },
        save(data) {
            return request({
                url: '/' + repository + '/save',
                method: 'POST',
                data
            });
        }
    };
}
